using System;
using System.Collections.Generic;
using System.Text;
using GarageGames.Torque.T2D;
using GarageGames.Torque.Core;
using GarageGames.Torque.Materials;
using Microsoft.Xna.Framework;
using GarageGames.Torque.Sim;

using Xyne.Templates.PuzzlePieceTemplate;
using Microsoft.Xna.Framework.Graphics;
using GarageGames.Torque.XNA;
using GarageGames.Torque.MathUtil;

namespace Xyne.Templates
{
    public class Wizard : T2DAnimatedSprite
    {
        private const int NumberCastCells = 18;
        private static Wizard template = new Wizard();

        public static Wizard Template
        {
            get { return template; }
        }

        public Wizard()
        {
            // Set the template and name
            IsTemplate = true;
            Name = Game.CharacterName;

            // Various parameters
            CreateWithWorldLimit = true;
            SimpleMaterial material = new SimpleMaterial();
            Texture2D texture = TorqueEngineComponent.Instance.Game.Content.Load<Texture2D>(@".\data\images\characters\wizard\cast");
            material.SetTexture(texture);
            T2DAnimationData data = new T2DAnimationData();
            CellCountDivider divider = new CellCountDivider();
            divider.CellCountX = NumberCastCells;
            divider.CellCountY = 1;
            material.TextureDivider = divider;
            data.Material = material;
            data.AnimationDuration = 1.0f;
            data.AnimationFrames = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17";
            data.Init();
            AnimationData = data;

            CollisionsEnabled = true;
            Size = new Vector2(texture.Width / NumberCastCells, texture.Height);
            Layer = Game.CharacterLevel;
            ObjectType = TorqueObjectDatabase.Instance.GetObjectType(Name);
        }

        public override void CopyTo(TorqueObject obj)
        {
            Wizard wizard = obj as Wizard;

            base.CopyTo(wizard);

            ProcessList.Instance.AddTickCallback(wizard, (ITickObject)wizard, 0);
        }

        public void PartlyLoopAnimation()
        {
            SetAnimationFrame((uint)12);
            ResumeAnimation();
        }
    }
}
